package pack;
import java.util.Scanner;

public class searchs
{
	public static void randomArr(int arr[])
	{
		for(int k = 0; k < arr.length; k++)
			arr[k] = (int)(Math.random()*arr.length);
	}
	
	public static void printArr(int arr[])
	{
		for(int k = 0; k < arr.length; k++)
			System.out.print(arr[k] + " ");
		System.out.println();
	}
	
	public static void main(String[] args)
	{
		int num = 100;
		int arr[] = new int[num];
		
		randomArr(arr);
		sort.qSort(arr);
		printArr(arr);
		
		Scanner cin = new Scanner(System.in);
		System.out.print("Print find number: ");
		int enter = cin.nextInt();
		
		System.out.println("Enter: " + enter);
		
		System.out.println("Number: " + binarySearch(arr, enter));
	}

	public static int binarySearch(int arr[], int enter)
	{
        return binarySearch(arr, enter, 0, arr.length-1);
	}    
    private static int binarySearch(int[] arr, int enter, int left, int right)
    {
        if(left > right) return -1;
        
        int mid = left + (right - left) / 2;
        
        if(enter < arr[mid])
            return binarySearch(arr, enter, left, mid-1);
        else if(enter > arr[mid])
            return binarySearch(arr, enter, mid+1, right);
        else
            return mid;
    }
}
